package pos.domain;

import java.util.List;

import pos.data.JDBCEntityDAO;
import pos.data.JDBCTypeDAO;

public class TypeStore {

	@SuppressWarnings("unused")
	private List<Type> types;
	private static TypeStore typeStore;

	public static synchronized TypeStore getInstance() {
		typeStore = new TypeStore();

		return typeStore;
	}

	public TypeStore() {
		types = (new JDBCTypeDAO()).getAllTypes();
	}

	public List<Type> getTypes() {
		// return types;
		return (new JDBCTypeDAO()).getAllTypes();
	}

	public Type getTypeById(String idType) {
		return (new JDBCTypeDAO()).getTypeById(idType);
	}

	public Type getTypeByEntity(Entity entity) {
		return (new JDBCTypeDAO()).getTypeByEntity(entity.getId());
	}

	public Type getTypeByName(String name) {
		return (new JDBCTypeDAO()).getTypeByName(name);
	}
	
	public List<SubType> getAllSubTypesByEntityAndType(Type type, Entity entity){
		return new JDBCTypeDAO().getSubTypesByEntityAndType(type.getId(),entity.getId());
	}

	public Type insertType(Type type, Entity entity) {
		return new JDBCTypeDAO().insertType(type, entity.getId());
	}

	public void removeEntity(Entity entity) {
		// didn't remove the associations because the objective is to have data
		new JDBCEntityDAO().removeEntity(entity);
	}
	
	public boolean existType(Type type, Entity entity){
		return new JDBCTypeDAO().existType(type.getName(), entity.getId());
	}
}
